package cn.sxt.common.userscenter.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.common.userscenter.util.ConstantFinalUtil;
import cn.sxt.common.userscenter.util.DateFormatUtil;
import cn.sxt.common.userscenter.util.EncrptUtil;
import cn.sxt.common.userscenter.util.FileUtil;
import cn.sxt.common.userscenter.util.RegexUtil;
import cn.sxt.common.userscenter.util.SpringEmailUtil;
import cn.sxt.common.userscenter.util.VerifyCodeUtils;

public class BaseController {

	@Resource
	protected SpringEmailUtil springEmailUtil;
	@Resource
	protected RegexUtil regexUtil;
	@Resource
	protected FileUtil fileUtil;
	/* 密码加密 */
	@Resource
	protected EncrptUtil encrptUtil ;
	/* 提示信息 */
	protected String info ;
	/* 日期转换 */
	@Resource
	protected DateFormatUtil dateFormatUtil;
	/**
	 * 加载验证码图片
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/randImg")
	public String randImg(HttpServletRequest request,HttpServletResponse response) throws Exception
	{
		response.setHeader("Pragma", "No-cache");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setDateHeader("Expires", 0);  
        response.setContentType("image/jpeg");  
          
        //生成随机字串  
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);  
        //存入会话session  
        HttpSession session = request.getSession();  
        session.setAttribute("rand", verifyCode.toLowerCase());  
        //生成图片  
        int w = 200, h = 80;  
        VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		return null ; 
	}
	
	/**
	 * 公共的错误信息展示页面
	 * @return
	 */
	@RequestMapping("/info")
	public String info(){
		ConstantFinalUtil.LOGGER.info("------- info -------");
		return "/head/info";
	}
	
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	} 
	
}
